package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bean.acgBeanVo.BaseData;
import com.kuang.demo.bean.lhf.Ad;
import com.kuang.demo.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("admin/ad")
public class AdController {

    @Autowired
    AdService adService;

    @RequestMapping("list")
//    public BaseRespVo list(@RequestParam Map data){
    public BaseRespVo list(Integer page, Integer limit, String sort, String order, String name, String content){
       //获取所需数据
        BaseData data = adService.queryAdList(page, limit, sort, order,name,content);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Ad ad){
        //获取当前时间并给到Bo对象
        ad.setUpdateTime(new Date());
        adService.updateAd(ad);
        return BaseRespVo.ok(ad);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Ad ad){
        adService.deletedelete(ad);
        return BaseRespVo.ok();
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Ad ad){
        Ad vo = adService.create(ad);
        return BaseRespVo.ok(vo);
    }

}
